import router from '.'
import store from '../store'
const whiteList = ['/login','/home'];
import {setLoginBackUrl} from '../cookie'
import {getToken} from "../cookie";

router.beforeEach((to, from, next) => {
    // let loginToken = store.getters.loginToken
    let loginToken = getToken()
    let path = to.path
    if (whiteList.indexOf(path)>-1 || loginToken) {//已经登录或者处于白名单免登录
        next();
    } else { //跳转到登录前，记录当前位置，登录之后需要跳转回来
        //cookie记录当前位置
        setLoginBackUrl(to.fullPath)
        //跳转到登录
        router.push({
            path:'/login'
        })
    }
})
